# encoding: utf-8
class TutorialCategoriesController < ApplicationController
	
	before_filter :load_sidebar
	before_filter :require_moderator, :except => [:index, :show]
	before_filter :do_index, :only => [:index, :show]

	# prikaz svih kategorija 
	def index
		@tutorial_categories = TutorialCategory.all

		@meta_description = "Želite naučiti nešto novo vezano uz programiranje ili dizajn? Probajte naše kratke online tečajeve."
		@meta_title = "Tutoriali | Udruga dizajnera i programera"
	end
	
	# prikaz svih kategorija u administracijskom sucelju
	def index_admin
		@tutorial_categories = TutorialCategory.all
	end
	
	# prikaz pojedine kategorije
	def show
		@tutorial_category = TutorialCategory.where( :slug => params[:slug] ).first

		@meta_title = @tutorial_category.name + " | Tutoriali"
		@meta_description = @tutorial_category.description
	end

	# brazac za stvaranje kategorije
	def new
		@tutorial_category = TutorialCategory.new

		respond_to do |format|
			format.html # new.html.erb
			format.xml  { render :xml => @tutorial_category }
		end
	end

	# GET /tutorial_categories/1/edit
	def edit
		@tutorial_category = TutorialCategory.find(params[:id])
	end

	# POST /tutorial_categories
	# POST /tutorial_categories.xml
	def create
		@tutorial_category = TutorialCategory.new(params[:tutorial_category])

		if @tutorial_category.save
			redirect_to(tutorial_categories_path, :notice => 'Nova kategorija je stvorena')
		else
			render :action => "new"
		end
	end

	# PUT /tutorial_categories/1
	# PUT /tutorial_categories/1.xml
	def update
		@tutorial_category = TutorialCategory.find(params[:id])

		respond_to do |format|
			if @tutorial_category.update_attributes(params[:tutorial_category])
				format.html { redirect_to(@tutorial_category, :notice => 'Kategorija tutoriala je izmjenjena.') }
				format.xml  { head :ok }
			else
				format.html { render :action => "edit" }
				format.xml  { render :xml => @tutorial_category.errors, :status => :unprocessable_entity }
			end
		end
	end

	# DELETE /tutorial_categories/1
	# DELETE /tutorial_categories/1.xml
	def destroy
		@tutorial_category = TutorialCategory.find(params[:id])
		@tutorial_category.destroy

		respond_to do |format|
			format.html { redirect_to(tutorial_categories_url) }
			format.xml  { head :ok }
		end
	end
end
